#include "BattleState.h"
#include "../StateMachine/stdafx.h"
#include "FightSM.h"

	FightMainLoop* FightMainLoop::Instance()
	{
		static FightMainLoop instance;

		return &instance;
	}

	void FightMainLoop::Enter(FightSM* pMiner)
	{
	}

	void FightMainLoop::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightMainLoop::Exit(FightSM* pMiner)
	{ 
	}

	bool FightMainLoop::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		switch(sm)
		{
		case MOUSE_LEFT_CLICKED:

			D3DXVECTOR3 wpos=D3DXVECTOR3(0.0f,0.0f,0.0f);
			int32 fid=-1;
			vector<boost::any> any;
			any.push_back(&wpos);
			any.push_back(&fid);
			pMiner->sendMessage("GetCellPos",&any);
			if(wpos!=D3DXVECTOR3(0.0f,0.0f,0.0f))
			{
				pMiner->sendMessage("AddBattleMenu",wpos);
				pMiner->m_curFigCell=wpos;
				pMiner->sendMessage("CurActFig",fid);
				pMiner->GetFSM()->ChangeState(FightMenu::Instance());
			}
			else
			{
				pMiner->sendMessage("DeleteBattleMenu");
			}
			break;
		}
		return true;
	}

	FightMenu* FightMenu::Instance()
	{
		static FightMenu instance;

		return &instance;
	}

	void FightMenu::Enter(FightSM* pMiner)
	{
	}

	void FightMenu::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightMenu::Exit(FightSM* pMiner)
	{ 
	}

	bool FightMenu::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		D3DXVECTOR2 pos=boost::any_cast<D3DXVECTOR2>(*iter);
		vector<boost::any> tmp;
		FIGHT_MENU fm;
		switch(sm)
		{
		case MOUSE_LEFT_CLICKED:
			tmp.push_back(pos);
			tmp.push_back(&fm);
			pMiner->sendMessage("ClickedMenu",&tmp);
			switch(fm)
			{
			case MATTACK:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightAttack::Instance());	
				break;
			case MCOMSKILL:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightComSkill::Instance());	
				break;
			case MGUARD:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightGuard::Instance());
				break;
			case MMAGIC:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightMagic::Instance());
				break;
			case MMOVE:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightMove::Instance());
				break;
			case MPROPS:
				pMiner->sendMessage("DeleteBattleMenu");
				pMiner->GetFSM()->ChangeState(FightProps::Instance());
				break;
			case NONE:
				break;
			}
			break;
		case MOUSE_RIGHT_CLICKED:
			pMiner->sendMessage("DeleteBattleMenu");
			pMiner->m_curFigCell=D3DXVECTOR3(0.0f,0.0f,0.0f);
			pMiner->GetFSM()->ChangeState(FightMainLoop::Instance());
			break;

		}
		return true;
	}

	
	FightAttack* FightAttack::Instance()
	{
		static FightAttack instance;

		return &instance;
	}

	void FightAttack::Enter(FightSM* pMiner)
	{
	}

	void FightAttack::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightAttack::Exit(FightSM* pMiner)
	{ 
	}

	bool FightAttack::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		return true;
	}

	
	FightMove* FightMove::Instance()
	{
		static FightMove instance;

		return &instance;
	}

	void FightMove::Enter(FightSM* pMiner)
	{
		pMiner->sendMessage("ClickedMoveMenu");
	}

	void FightMove::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightMove::Exit(FightSM* pMiner)
	{ 
	}

	bool FightMove::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		bool rt=false;
		vector<boost::any> tmp;
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		switch(sm)
		{
		case MOUSE_LEFT_CLICKED:
			tmp.push_back(&rt);
			pMiner->sendMessage("ClickedMovePos",&tmp);
			if(rt)
			{
				pMiner->sendMessage("ClearMoveCell");
				pMiner->m_curFigCell=D3DXVECTOR3(0.0f,0.0f,0.0f);
				pMiner->GetFSM()->ChangeState(FightMainLoop::Instance());
			}
			break;
		case MOUSE_RIGHT_CLICKED:
			pMiner->sendMessage("ClearMoveCell");
			pMiner->sendMessage("AddBattleMenu",pMiner->m_curFigCell);
			pMiner->GetFSM()->ChangeState(FightMenu::Instance());
			break;
		}
		return true;
	}

	
	FightComSkill* FightComSkill::Instance()
	{
		static FightComSkill instance;

		return &instance;
	}

	void FightComSkill::Enter(FightSM* pMiner)
	{
	}

	void FightComSkill::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightComSkill::Exit(FightSM* pMiner)
	{ 
	}

	bool FightComSkill::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		return true;
	}

	
	FightMagic* FightMagic::Instance()
	{
		static FightMagic instance;

		return &instance;
	}

	void FightMagic::Enter(FightSM* pMiner)
	{
	}

	void FightMagic::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightMagic::Exit(FightSM* pMiner)
	{ 
	}

	bool FightMagic::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		return true;
	}

	
	FightGuard* FightGuard::Instance()
	{
		static FightGuard instance;

		return &instance;
	}

	void FightGuard::Enter(FightSM* pMiner)
	{
	}

	void FightGuard::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightGuard::Exit(FightSM* pMiner)
	{ 
	}

	bool FightGuard::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		return true;
	}

	
	FightProps* FightProps::Instance()
	{
		static FightProps instance;

		return &instance;
	}

	void FightProps::Enter(FightSM* pMiner)
	{
	}

	void FightProps::Execute(FightSM* pMiner)
	{ 
	
	}

	void FightProps::Exit(FightSM* pMiner)
	{ 
	}

	bool FightProps::OnMessage(FightSM* pMiner,boost::any p)
	{
		vector<boost::any>* any=boost::any_cast<vector<boost::any>*>(p);
		vector<boost::any>::iterator iter=any->begin();
		_SYSTEM_MESSAGE sm=boost::any_cast<_SYSTEM_MESSAGE>(*iter++);
		return true;
	}